// pages/main/main.js
const app = getApp()
var uniacid = wx.getStorageSync('live') ? wx.getStorageSync('live')['live'].uniacid : ''
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: "火蝶信息科技",
    canShow: 0,
    tapTime: '', // 防止两次点击操作间隔太快
    entryInfos: [],
    headerHeight: app.globalData.headerHeight,
    statusBarHeight: app.globalData.statusBarHeight,
    isTimeHide:false,
    bottonShow:false
  },

  onEntryTap: function (e) {


    console.log( '点击传递', e.currentTarget)

    
    if(e.currentTarget.id == 1){
      wx.switchTab({
        url: '../mlvb-live-room-demo/room-list-page/roomlist',
      })
    }
    if (this.data.canShow) {
      
      // 防止两次点击操作间隔太快
      var nowTime = new Date();
      if (nowTime - this.data.tapTime < 1000) {
        return;
      }
    
      this.setData({
        'tapTime': nowTime
      });
    } else {
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后再试。',
        showCancel: false
      });
    }
    if (e.currentTarget.id == 0) {
      var live = wx.getStorageSync("live");
      var live = live['live'];
      if (live['playerpush'] == 'undefined') {
        wx.showToast({
          title: "您还未开通直播功能",
          icon: "none",
          duration: 2000
        });
        return;

      }
      wx.navigateTo({
        url: "../live-pusher-demo/push-config/push-config",
      });
    }
  
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    console.log("onLoad");
    var live = wx.getStorageSync("live");
    var user = live['user'];
    var detailarr = live['detailarr'];
 
    var arr = [];
    wx.request({
      url:`https://dev.huodiesoft.com/bossdataapi.php?action=service_endtime`,
      data:{
        uniacid:"53"
      },
      header:{},
      method:'post',
      dataType:'json',
      responseType: 'text',
      success(res){
        console.log(res)
      }
    })
    if (detailarr.Live == 1) {

      let show = this.data.bottonShow
      this.setData({
        bottonShow:!show
      })

      arr.push({
        index:0,
        title: "拼团直播主播助手",
        desc: "拼团吸粉裂变直播解决体验",
        navigateTo: "../live-pusher-demo/push-config/push-config",
        url: "https://res.lexiangpingou.cn/images/53/2019/12/m2U10JBFSG4q41ksbuSQ1g22tGfkTQ.png"
       
      })
    }
    
      this.setData({
      name: user['name'],
      endtime: user['endtime'],
      entryInfos:arr,
    });
  },
  isTimeHide:function(){
    let isTimeHide = this.data.isTimeHide
    this.setData({
      isTimeHide:!isTimeHide
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    console.log("onReady");
    if (!wx.createLivePlayerContext) {
      setTimeout(function () {
        wx.showModal({
          title: '提示',
          content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后再试。',
          showCancel: false
        });
      }, 0);
    } else {
      // 版本正确，允许进入
      this.data.canShow = 1;
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log("onShow");

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    console.log("onHide");

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    console.log("onUnload");

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log("onPullDownRefresh");

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("onReachBottom");

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    console.log(" onShareAppMessage");
    return {
      // title: 'RTMP推流',
      // path: '/pages/push/push',
      path: "pages/home-login/main",
      imageUrl: "https://res.lexiangpingou.cn/images/applet/hd_product_introduce.png"
    };
  },
  loginout() {
    wx.navigateTo({
      url: '/pages/home-login/main',
    })
  },
  startLive(e){
    console.log('开启直播',e)
    wx.navigateTo({
      url: '../live-pusher-demo/push-config/push-config',
    })
  },
  Tel() {
    wx.makePhoneCall({
      phoneNumber: '4006261079',
    })
  },
  goHDY(){
    let url = "https://www.lexiangpingou.cn/"

    wx.navigateTo({
      url: '../webwiew/webwiew?url='+encodeURIComponent(url),
    })
  },
 

})